﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using ConfigLibrary;
using System.Runtime.Serialization.Formatters.Binary;



namespace WindowsFormsApplication1
{
    public partial class CIreport : Form
    {
        public CIreport()
        {
            InitializeComponent();
            getconfig();
            login();
        }

        private void getconfig()
        {
            Stream s = File.Open(Properties.Settings.Default.CONFIGTEST, FileMode.Open);
            BinaryFormatter b = new BinaryFormatter();
            Config config = (Config)b.Deserialize(s);
            s.Close();
            config.GetEddsInfo(out _user, out _pass);
        }



        private void login()
        {
            try
            {
                ci.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(logon_DocumentCompleted);
                ci.AllowNavigation = true;
                ci.Navigate("https://wal-mart-us.evocoworkspace.com/Public/Login.aspx?ReturnUrl=%2fApplication%2fProjects%2fDefault.aspx", false);                
            }
            catch
            {

            }
        }        

        void logon_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            switch (task)
            {
                case 0:             
                    ci.Document.GetElementById("ctl00_mainContent_loginTextBox").SetAttribute("value", _user);
                    ci.Document.GetElementById("ctl00_mainContent_passwordTextBox").SetAttribute("value", _pass);
                    ci.Document.GetElementById("ctl00_mainContent_loginButton").InvokeMember("click");                                  
                    task++;                    
                break;

                case 1:
                    ci.Navigate("http://wal-mart-us.evocoworkspace.com/Application/project/default.aspx?FolderID=724d068e-5c91-4313-9217-1da5a0efeb8c", false);
                    ci.Show();
                    
                    
                    //object[] url = null;
                    //url[0] = "http://wal-mart-us.evocoworkspace.com/Application/project/default.aspx?FolderID=724d068e-5c91-4313-9217-1da5a0efeb8c";
                    //ci.Document.InvokeScript("LinkRedirect", url);                                 
                break;
                case 2:

                break;
            }        
        }

        void cifolder_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            
        }

        WebBrowser ci = new WebBrowser();
        WebBrowser cifolder = new WebBrowser();
        public string _user;
        public string _pass;
        public int task = 0;
        
    }
}
